<?php
//和ajax_page.html配套(获取数据)
$init = $_POST["init"];
$total=$_POST["total"];
$start = ($init-1)*5;
$pdo = new PDO("mysql:host=127.0.0.1;dbname=news","root","keyan");
$pdo->exec("set names utf8");
$sql = "select articleId,title from newsarticles limit $start,5 ";
$pdos= $pdo->query($sql);
$arr = $pdos->fetchAll(PDO::FETCH_ASSOC);
//初始加载求总页数
if($total=="total"){
	$sql2 = "select count(1) num from newsarticles";
	$pdos2= $pdo->query($sql2);
	$arr2 = $pdos2->fetch(PDO::FETCH_ASSOC);
	$totalpage=ceil($arr2["num"]/5);
	$arr[0]['total']=$totalpage;
}
//将数组转化为json串
echo json_encode($arr);
//json_decode($json);//这是将json串转回数组